package za.org.jcicada.datastore.impl;

import java.lang.reflect.Constructor;
import java.net.URI;
import java.net.URISyntaxException;

import za.org.jcicada.confss.impl.ConfssDynamicConfiguration;

public class DataStoreDynamicConfiguration extends ConfssDynamicConfiguration {
	public String datastoreURLs = "tcp://ANYADDR:0";
	public String dataStoreServerClass = "za.org.jcicada.datastore.impl.MemoryDataStoreServer";
	public String connectionString = "";
    public String rateStatusStrategy = "Int:0=>WARN,65535=>NOMINAL";
    public String statusRateStatusStrategy = "Int:65535=>NOMINAL";
	public URI getConnectionURI() throws URISyntaxException {
		return new URI(connectionString);
	}
	public DataStoreServerAbstract getDataStoreServer() throws Exception {
		Class<?> clazz = Class.forName(dataStoreServerClass);
		Class<?>[] parameterTypes = new Class<?>[0];
		Constructor<?> ct = clazz.getConstructor(parameterTypes);
		Object[] initargs = new Object[0];
		DataStoreServerAbstract dataStoreServer = (DataStoreServerAbstract) ct.newInstance(initargs);
		dataStoreServer.initialize(getConnectionURI());
		return dataStoreServer;
	}
}
